<?php

/**
*
* @package DND Charlist
* @version $Id: dnd_list_chars.php$
* @copyright (c) 2010 Stephan "MOTU" König
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/



// Benötigte Dateien und Variablen von phpBB
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Session auslesen und Benutzer-Informationen laden
$user->session_begin();
$user->setup();
$auth->acl($user->data);

$user->setup('mods/info_dnd_list_chars');

// Initial var setup
$user_id	= request_var('u', ANONYMOUS);
$username	= request_var('un', '', true);
$char_data = array();
$chars = array();
$i = 0;

/*
* Inhaltsbereich
*/

// Header und Titel der Seite
page_header('DnD Char List');

// Angabe eurer Content-Seite
$template->set_filenames(array(
	'body' => 'dnd_list_chars.html')
);

if ($user->data['user_id'] == ANONYMOUS)
{
	// Code, wenn Benutzer nicht angemeldet ist
	login_box();
}
else
{
	// Code, wenn Benutzer angemeldet ist
	
	if(ISSET($_GET['ORDER']) && ISSET($_GET['DESC']))
	{
		$dndList->getList(0,array('order_by' => strval($_GET['ORDER']),'desc' => $_GET['DESC']));
	}	
	else if(ISSET($_GET['ORDER']) && !ISSET($_GET['DESC']))
	{
		$dndList->getList(0,array('order_by' => strval($_GET['ORDER']),'desc' => 0));
		
	}
	else
	{
		$dndList->getList(0,array('order_by' => 'name','desc' => 0));
	}
	
	$template->assign_vars(array(
		'U_ORDER_BY_NAME_A'	=> append_sid($phpbb_root_path.'dnd_list_chars.'.$phpEx, array('ORDER' => 'name', 'DESC' => '0')),
		'U_ORDER_BY_NAME_D'	=> append_sid($phpbb_root_path.'dnd_list_chars.'.$phpEx, array('ORDER' => 'name', 'DESC' => '1')),
		'U_ORDER_BY_RACE_A'	=> append_sid($phpbb_root_path.'dnd_list_chars.'.$phpEx, array('ORDER' => 'race', 'DESC' => '0')),
		'U_ORDER_BY_RACE_D'	=> append_sid($phpbb_root_path.'dnd_list_chars.'.$phpEx, array('ORDER' => 'race', 'DESC' => '1')),
		'U_ORDER_BY_GRP_A'	=> append_sid($phpbb_root_path.'dnd_list_chars.'.$phpEx, array('ORDER' => 'grp', 'DESC' => '0')),
		'U_ORDER_BY_GRP_D'	=> append_sid($phpbb_root_path.'dnd_list_chars.'.$phpEx, array('ORDER' => 'grp', 'DESC' => '1')),
	));
	foreach ($dndList->getChars() as $row)
	{
		
		$ovlevel = $dndList->getOverallLevel($row['id']);
		$template->assign_block_vars('list_chars', array(
			'U_CHAR_LINK'		=> $row['char_link'],
			'CHAR_NAME'			=> $row['name'],
			'RACE'				=> $row['race'],
			'GROUP'				=> $row['grp'],
			'INFO'				=> $row['char_info'],
			'CHAR_ID'			=> $row['id'],
			'OVLEVEL'			=> $ovlevel,
		));
		foreach ($row['char_classes'] as $row2)
		{
			
			$template->assign_block_vars('list_chars.list_classes', array(
				'CLASS_NAME'		=> $row2['name'],
				'CLASS_LVL'			=> $row2['level'],
			));
		}
		$dndList->freeCharClasses();
	}
}

// Footer
page_footer();

?>